home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1249 / instab.t < prev    next >
Text File  |  1997-04-18  |  2KB  |  100 lines

  1. %
  2. % "instab.t" compresses text files by inserting tabs
  3. %
  4. %   Sample program for the T Interpreter by:
  5. %
  6. %   Stephen R. Schmitt
  7. %   962 Depot Road
  8. %   Boxborough, MA 01719
  9. %
  10.  
  11. const Out_file_name : string := "instab.fil"
  12. const Tab_size : int := 8
  13.  
  14. var In_file_name : string
  15. var In_file, Out_file : int
  16. var Line: string
  17.  
  18.  
  19. program
  20.  
  21.     prompt "name of file to compress:"
  22.     get In_file_name 
  23.  
  24.     In_file := open( In_file_name, "r" )
  25.     Out_file := open( Out_file_name, "w" )
  26.  
  27.     assert In_file ~= 0 and Out_file ~= 0
  28.  
  29.     loop
  30.  
  31.         exit when eof( In_file ) 
  32.         get : In_file, Line : *
  33.         put : Out_file, insert_tabs( Line )
  34.  
  35.     end loop
  36.  
  37.     if close( In_file ) = 0 or close( Out_file ) = 0 then
  38.  
  39.         put "file close error"
  40.  
  41.     end if
  42.  
  43.     put In_file_name, " -> ", Out_file_name 
  44.  
  45. end program
  46.  
  47.  
  48. function insert_tabs( in : string ) : string
  49.  
  50.     var i, j, k : int
  51.     var tab : boolean
  52.     var out : string
  53.  
  54.     j := 0
  55.  
  56.     for i := 0...255 do
  57.  
  58.         exit when in[i] = '\0'
  59.  
  60.         if in[i] = ' ' then
  61.  
  62.             tab := true
  63.  
  64.             for k := 1...Tab_size - 1 do
  65.  
  66.                 if in[i+k] ~= ' ' then
  67.  
  68.                     tab := false
  69.                     exit
  70.  
  71.                 end if
  72.  
  73.             end for
  74.  
  75.             if tab then
  76.  
  77.                 out[j] := '\t'            % ascii tab character
  78.                 i := i + Tab_size - 1
  79.  
  80.             else
  81.  
  82.                 out[j] := in[i]
  83.  
  84.             end if
  85.  
  86.         else
  87.  
  88.             out[j] := in[i]
  89.  
  90.         end if
  91.  
  92.         incr j
  93.  
  94.     end for
  95.  
  96.     out[j] := '\0'
  97.  
  98.     return out
  99.  
  100. end function